<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<p>We delay focus until mouse up if the mouse down occurs inside a focusable
node that is inside an already focused node. But we shouldn't delay focus unless
the mouse down occurs in an already focused node.</p>
<p>To run manually,
<ol>
<li>Select everything from 'foo' though 'baz'</li>
<li>Mouse down inside the text field.</li>
<li>The text field should be focused.</li>
</ol>
</ol>
</p>
<div id="div"><div>foo</div><input type="text" id="field"><div>baz</div></div>
<div id="log"></div>
<script>
test(function() {
    if (window.eventSender)
        return;
    var field = document.getElementById('field');
    var div = document.getElementById('div');
    var selection = window.getSelection();
    selection.collapse(div, 0);
    selection.extend(div, div.childNodes.length);

    var x = field.offsetParent.offsetLeft + field.offsetLeft + field.offsetWidth / 2;
    var y = field.offsetParent.offsetTop + field.offsetTop + field.offsetHeight / 2;
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();

    assert_equals(document.activeElement, field, 'activeElement');
});
</script>
